// 请求js
// 引入配置好的axios
import api from './api'
import http from './http'

export function userLogin(data) {
    return http({
        method: 'POST',
        url: api.login,
        data
    })
    //返回promise对象
}


export function userRegister(data) {
    return http({
        method: 'POST',
        url: api.register,
        data
    })
    //返回promise对象
}


export function demo() {
    return http({
        method: "GET",
        url: api.address,
    })
}

// 请求商品列表
export function getGoods(data) {
    return http({
        method: "GET",
        url: api.goods,
        params: data
    })
}

export function carousel(data) {
    return http({
        method: "GET",
        url: api.carousel,
        params: data
    })
}

//请求单个信息
export function singleGood(id) {
    return http({
        method: "GET",
        url: `${api.goods}/${id}`
    })
}

//请求单个信息
export function classifyGoods(data) {
    return http({
        method: "GET",
        url: api.classifyGoods,
        params: data
    })
}

// 添加购物车
export function shoppingToCart(data) {
    return http({
        method: "post",
        url: api.shoppingCart,
        data
    })
}

// 查看购物车信息
export function getCart(data) {
    return http({
        method: "GET",
        url: api.shoppingCart,
        params: data
    })
}

// 更新购物车数据
export function updateCart(id, data) {
    return http({
        method: "PUT",
        url: api.shoppingCart + '/' + id,
        data
    })
}


// 更新购物车数据
export function deleteCart(id) {
    return http({
        method: "DELETE",
        url: api.shoppingCart + '/' + id,
    })
}


// 添加地址
export function addAddress(data) {
    return http({
        method: "post",
        url: api.address,
        data
    })
}

// 获取所有城市
export function getCity() {
    return http({
        method: "GET",
        url: api.city,
    })
}


// 获取地址
export function getAddress() {
    return http({
        method: "get",
        url: api.address
    })
}



// 删除地址数据
export function deleteAddress(id) {
    return http({
        method: "DELETE",
        url: api.address + '/' + id,
    })
}


// 更新地址数据
export function updateAddress(data, id) {
    return http({
        method: "PUT",
        url: api.address + '/' + id,
        data
    })
}

// 添加订单
export function addOrderRequest(data) {
    return http({
        method: "post",
        url: api.order,
        data
    })
}

// 查看订单列表
export function getOrderListgRequest(data) {
    return http({
        method: "get",
        url: api.order,
        params: data
    })
}

//获取单个商品的清单
export function getSinglOrdergRequest(id) {
    return http({
        method: "get",
        url: api.order + '/' + id
    })
}

//删除订单
export function deleteSinglOrdergRequest(id) {
    return http({
        method: "DELETE",
        url: api.order + '/' + id
    })
}